package com.hp.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.hp.ssm.entity.Doctor;
import com.hp.ssm.entity.Hospital;
import com.hp.ssm.entity.User;
import com.hp.ssm.service.DoctorService;
import com.hp.ssm.util.GeneratID;
import com.hp.ssm.util.ResultJson;
import com.hp.ssm.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/doctor")
public class DoctorController {
    @Autowired
    private DoctorService doctorService;

    //可以操作的列表
    @RequestMapping("/showhospital")
    public ModelAndView showAll(Doctor doctor,Integer page,Integer limit, HttpServletResponse resp) {
        ModelAndView mv = new ModelAndView();
        System.out.println(doctor + "-------------");
        List<Doctor> list = doctorService.showAll(doctor,page,limit);
        PageInfo<Doctor> userPageInfo = new PageInfo<Doctor>(list);
        System.out.println(list + "----------------------------------------------");
        ResultJson success = ResultJson.success(userPageInfo);
        Utils.returnJson(success, resp);
        return mv;
    }
    //假删除的列表
    @RequestMapping("/showhospital2")
    public ModelAndView showAll2(Doctor doctor,Integer page,Integer limit, HttpServletResponse resp) {
        ModelAndView mv = new ModelAndView();
        List<Doctor> list = doctorService.showAll2(doctor,page,limit);
        PageInfo<Doctor> userPageInfo = new PageInfo<Doctor>(list);
        System.out.println(list + "----------------------------------------------");
        ResultJson success = ResultJson.success(userPageInfo);
        Utils.returnJson(success, resp);
        return mv;
    }


    @RequestMapping("/findId")
    public ModelAndView findId(int did, HttpServletRequest req, HttpServletResponse resp) {
        Doctor p = doctorService.findId(did);
        System.out.println(p + "<<<<<<<<<id>>>>>>>>>");
        ModelAndView modelAndView = new ModelAndView();
        ResultJson success = ResultJson.success(p);
        Utils.returnJson(success, resp);
        return null;
    }


    @RequestMapping("/insert")
    public String insert(Doctor doctor, HttpServletResponse resp) throws Exception {
        String dpuser = GeneratID.getGeneratID();
         doctor.setDpuser(dpuser);
        Date dtime = new Date();
        doctor.setDtime(dtime);
        System.out.println(doctor);
        int i = doctorService.insert(doctor);
        System.out.println(i + "----------222--------");
        ResultJson success = ResultJson.success(i);
        Utils.returnJson(success, resp);
        return null;
    }

    @RequestMapping("/update")
    public String update(Doctor doctor, HttpServletResponse resp) throws Exception {
        int i = doctorService.updateStatus(doctor);
        System.out.println(i + "----------111--------");
        ResultJson success = ResultJson.success(i);
        Utils.returnJson(success, resp);
        return null;
    }
    @RequestMapping("/del")
    public String del(Doctor doctor, HttpServletResponse resp) {
        int i = doctorService.del(doctor);
        System.out.println(i + "----------111--------");
        ResultJson success = ResultJson.success(i);
        Utils.returnJson(success, resp);
        return null;
    }
    @RequestMapping("/reck")
    public String reck(Doctor doctor, HttpServletResponse resp){
        int i = doctorService.reck(doctor);
        System.out.println(i + "----------111--------");
        ResultJson success = ResultJson.success(i);
        Utils.returnJson(success, resp);
        return null;
    }
}
